<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AngularJS&middot;Hello AngularJS</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <link href="http://cdn.bootcss.com/bootstrap-datepicker/1.6.0/css/bootstrap-datepicker.min.css" rel="stylesheet">
    <style>
        .demo{
            margin-bottom:10px;
        }
    </style>
</head>
<body>
 <div class="container">
     <div class="row">
         <nav class="navbar navbar-default navbar-static-top">
             <div class="container-fluid">
                 <div class="navbar-header">
                     <a class="navbar-brand" href="../index.html">首页</a>
                 </div>
                 <ul class="nav navbar-nav">
                    <li class="active"><a href="javascript:void(0)">Link</a></li>
                    <li><a href="javascript:void(0)">Link2</a></li>
                 </ul>
             </div>
         </nav>
     </div>
     <div class="row demo" ng-app="MyAPP">
         <h3>Demo1: timepicker示例</h3>
         <!--<div ng-controller="DatePickerCtrl" class="date">-->
             <!--<input type='text' ng-model="myDate" data-picker/>-->
             <!--<button ng-click="setTime()">设置日期</button>-->
         <!--</div>-->
         <date-picker></date-picker>
     </div>
 </div>
 </div>
</body>
</html>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script src="http://cdn.bootcss.com/jquery/1.12.1/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap-datepicker/1.6.0/js/bootstrap-datepicker.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap-datepicker/1.6.0/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script>
    var app=angular.module("MyAPP",[]);
    app.directive('datePicker', ['$log', function($log){
        return {
            restrict: 'EA',
            templateUrl: './views/mydatepicker.html',
            replace: true,
            link: function(scope, element, attrs, controller) {
                var start,end;
                $(element).find('#starttime').datepicker({
                    format: 'yyyy-mm-dd',
                    weekStart: 1,
                    autoclose: true,
                    todayBtn: 'linked',
                    language: 'zh-CN'
                }).on('changeDate',function(ev){
                    start=ev.date.valueOf();
                    $log.info(start);
                    if(start<end){
                        alert("“开始时间 ”不能早于“结束时间 ” ！");
                        $("#starttime").focus();
                    }
                });
                $(element).find('#endtime').datepicker({
                    format: 'yyyy-mm-dd',
                    weekStart: 1,
                    autoclose: true,
                    todayBtn: 'linked',
                    language: 'zh-CN'
                }).on('changeDate',function(ev){
                    end = ev.date.valueOf();
                    $log.info(end);
                    if(end<start){
                        alert("“结束时间 ”不能早于“开始时间 ” ！");
                        $(this).focus();
                    }else{
                        alert("日期符合要求");
                    }
                });
            }
        }
    }]);
</script>
